from twisted.internet import reactorfrom pyspades.load import VXLDataimport osdef get_name(name):    return './maps/%s.saved.vxl' % namedef apply_script(protocol, connection, config):    class MapSaveProtocol(protocol):        def __init__(self, config, map):            if config.get('load_saved_map', False):                cached_path = get_name(map.name)                if os.path.isfile(cached_path):                    map.data = VXLData(open(cached_path, 'rb'))            protocol.__init__(self, config, map)            reactor.addSystemEventTrigger('before', 'shutdown', self.save_map)                def save_map(self):            open(get_name(self.map_info.name), 'wb').write(self.map.generate())    return MapSaveProtocol, connection